#include "Message.ClientMessage.h"
#include "Message.RequestWithoutResponse.h"
#include "Message.RequestWithResponse.h"

namespace AlgoTrading
{
	namespace Messages
	{

		ClientMessage::ClientMessage(std::auto_ptr<PBClientMessage>& message)
			: clientMessage(message)
		{
		}

		ClientMessage::~ClientMessage(void)
		{
		}

		void ClientMessage::Serialize(std::ostream& ostream) const
		{
			clientMessage->SerializeToOstream(&ostream);
		}

		std::auto_ptr<ClientMessage> ClientMessage::Deserialize(std::istream& istream)
		{
			std::auto_ptr<PBClientMessage> clientMessage(new PBClientMessage());
			clientMessage->ParseFromIstream(&istream);

			switch(clientMessage->type())
			{
				case PBClientMessage_Type_PBRequestWithResponse:
					return RequestWithResponse::Deserialize(clientMessage);
					break;
				case PBClientMessage_Type_PBRequestWithoutResponse:
					return RequestWithoutResponse::Deserialize(clientMessage);
					break;
			}

			return std::auto_ptr<ClientMessage>(0);
		}

		/*ClientMessage::ClientMessageType ClientMessage::GetClientMessageType()
		{
			switch(clientMessage->type())
			{
				case PBClientMessage_Type_PBRequestWithResponse:
					return REQUEST_WITH_RESPONSE;
				case PBClientMessage_Type_PBRequestWithoutResponse:
					return REQUEST_WITHOUT_RESPONSE;
			}
			return REQUEST_WITH_RESPONSE;
		}*/
	}
}